package cn.funnyxb.powerremember.uis.task.taskEdit.alarm;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import cn.funnyxb.powerremember.beans.ATask;
import cn.funnyxb.powerremember.beans.AlarmInfo;
import cn.funnyxb.powerremember.db.tables.Tbholder_tasksinfo;
import cn.funnyxb.tools.appFrame.App;
import cn.funnyxb.tools.appFrame.AppDBConfig;
import cn.funnyxb.tools.appFrame.database.DBHolder;
import cn.funnyxb.tools.appFrame.debugTool.Debuger;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

public class AlarmReceiver extends BroadcastReceiver
{
  public static final String EXTRANAME_ALARMINFO = "alarminfo";
  public static final String EXTRANAME_SURPASSGROUPNUM = "surpassgroupnum";
  public static final String EXTRANAME_TASKINFO = "taskinfo";
  private AlarmInfo ai;
  private DBHolder dbHolder = null;
  private int groupCnt_surpass;
  private Context mContext;
  private ATask taskInfo = null;

  private void alarm(int paramInt)
  {
    Toast.makeText(this.mContext, this.mContext.getString(2131034112) + this.mContext.getString(2131034130) + ":\n" + "\n" + this.mContext.getString(2131034273) + "(" + this.taskInfo.getName() + ")" + this.mContext.getString(2131034274), 1).show();
    Intent localIntent = new Intent(this.mContext, NotifyActivity.class);
    localIntent.setFlags(285474816);
    localIntent.putExtra("alarminfo", this.ai);
    localIntent.putExtra("state", paramInt);
    localIntent.putExtra("surpassgroupnum", this.groupCnt_surpass);
    localIntent.putExtra("taskinfo", this.taskInfo);
    this.mContext.startActivity(localIntent);
  }

  private void closeDB()
  {
    log("closeDB");
    if (this.dbHolder == null)
      return;
    this.dbHolder.closeDB();
  }

  private static void log(String paramString)
  {
    Debuger.log("alarmReceiver", paramString);
  }

  private boolean needAlarmOfWeek(AlarmInfo paramAlarmInfo)
  {
    Calendar localCalendar = Calendar.getInstance();
    localCalendar.setTimeInMillis(System.currentTimeMillis());
    int i = localCalendar.get(7) - 1;
    if (i == 0)
      i = 7;
    return paramAlarmInfo.getRepeatValueInBoolean()[(i - 1)];
  }

  private DBHolder prepareDbHolder()
  {
    DBHolder localDBHolder2;
    try
    {
      DBHolder localDBHolder1 = new DBHolder(this.mContext, "powerremember.db", AppDBConfig.DBVERSION, null);
      log("holder=" + localDBHolder1);
      this.dbHolder = localDBHolder1;
      localDBHolder2 = localDBHolder1;
      return localDBHolder2;
    }
    catch (Exception localException)
    {
      log("getDB exception" + localException);
      log("exception stack=" + localException.getStackTrace());
      localDBHolder2 = null;
    }
  }

  private ATask prepareTaskInfo()
  {
    ATask localATask;
    try
    {
      Tbholder_tasksinfo localTbholder_tasksinfo = new Tbholder_tasksinfo(this.dbHolder);
      this.taskInfo = localTbholder_tasksinfo.queryTaskInfoById(this.ai.getTaskId());
      localATask = this.taskInfo;
      return localATask;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      log("prepare TbHolder err");
      localATask = null;
    }
  }

  private boolean queryIsNeedAlarm()
  {
    int i = 1 + (int)(Math.ceil(System.currentTimeMillis() / 86400000L) - Math.ceil(this.taskInfo.getCreateDatetime() / 86400000L));
    this.groupCnt_surpass = (this.taskInfo.getGroupCnt_learned() - (i * this.taskInfo.getGroupOfOneDay()));
    if ((this.ai.isWorkOnlyWhenDelay()) && (this.groupCnt_surpass >= 0));
    for (int j = 0; ; j = 1)
      return j;
  }

  public void onReceive(Context paramContext, Intent paramIntent)
  {
    log("time come!");
    this.mContext = paramContext;
    this.ai = ((AlarmInfo)paramIntent.getExtras().getSerializable("alarminfo"));
    if (this.ai == null);
    while (true)
    {
      label33: return;
      log("ai=" + this.ai);
      if (prepareDbHolder() == null)
        log("getDBHolder Error");
      if (prepareTaskInfo() == null)
      {
        log("getTaskInfo Error");
        closeDB();
      }
      if (!(needAlarmOfWeek(this.ai)))
      {
        log("week repeat donot need alarm");
        closeDB();
      }
      if ((this.ai.isWorkOnlyWhenDelay()) && (!(queryIsNeedAlarm())))
        continue;
      closeDB();
      int i = -1;
      ActivityManager localActivityManager = (ActivityManager)paramContext.getSystemService("activity");
      int j = 0;
      Object localObject = null;
      Iterator localIterator = localActivityManager.getRunningTasks(7).iterator();
      while (true)
      {
        if (!(localIterator.hasNext()));
        while (true)
        {
          if (i != 0)
            break label260;
          log("run,and front!,app.getapp()=" + App.getApp());
          alarm(1);
          break label33:
          ActivityManager.RunningTaskInfo localRunningTaskInfo = (ActivityManager.RunningTaskInfo)localIterator.next();
          if (!(localRunningTaskInfo.topActivity.getPackageName().contains(paramContext.getPackageName())))
            break;
          localObject = localRunningTaskInfo;
          i = j;
        }
        ++j;
      }
      if (localObject != null)
      {
        label260: log("run,not front,app.getapp()=" + App.getApp());
        alarm(2);
      }
      log("not run,app.getapp()=" + App.getApp());
      alarm(3);
    }
  }
}

/* Location:           E:\Desktop\复件 classes_dex2jar.jar
 * Qualified Name:     cn.funnyxb.powerremember.uis.task.taskEdit.alarm.AlarmReceiver
 * JD-Core Version:    0.5.3
 */